#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
const int INF = 2e8+7;
int n, k;
int a[maxn], b[maxn];
bool check(int x) {
  for(int i=0; i<n; ++i) {
    if(a[i]>=x) b[i]=1;
    else if(a[i]<x) b[i]=-1;
  }
  for(int i=1; i<n; ++i) b[i]+=b[i-1];
  int mn=0, mx = b[k-1]; // The initial value of |mx| is EXTREMELY important
  for(int i=k; i<n; ++i) {
    mn = min(mn, b[i-k]);
    mx = max(mx, b[i]-mn);
  }
  return mx > 0;
}
int solve() {
  int l=0, r=maxn;
  int mid;
  while(l+1<r) {
    mid = (l+r)/2;
    if(check(mid)) l=mid;
    else r=mid;
  }
  cout<<l<<'\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin>>n>>k; for(int i=0; i<n; ++i) cin>>a[i];
  solve();
  return 0;
}

